package apa.data.samples;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class RowCount {
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Usage: java WordCount inputFile");
			System.exit(0);
		}
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(
					new FileInputStream(args[0])));
			int nrows = 0, minc = Integer.MAX_VALUE, maxc = Integer.MIN_VALUE;
			String line;
			while ((line = input.readLine()) != null) {
				++nrows;
				int nc = line.split(",").length;
				if (nc < minc)
					minc = nc;
				if (nc > maxc)
					maxc = nc;
			}
			input.close();
			System.out.println("Rows: " + nrows);
			System.out.println("Min columns: " + minc);
			System.out.println("Max columns: " + maxc);
		} catch (IOException e) {
			System.out.println(e.toString());
		}
	}
}
